package cc.mrbird.febs.cos.controller;


import cc.mrbird.febs.common.utils.R;
import cc.mrbird.febs.cos.entity.Contact;
import cc.mrbird.febs.cos.service.IContactService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author fanke
 */
@RestController
@RequestMapping("/cos/contact")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ContactController {

    private final IContactService contactService;

    /**
     * 分页查询
     * @param page
     * @param contact
     * @return
     */
    @GetMapping("/page")
    public R getBooKInfoByPage(Page page, Contact contact) {
        return R.ok(contactService.page(page, Wrappers.query(contact)));
    }

    /**
     * 新增
     * @param contact
     * @return
     */
    @PostMapping
    public R save(Contact contact) {
        return R.ok(contactService.save(contact));
    }

    /**
     * 修改
     * @param contact
     * @return
     */
    @PutMapping
    public R update(Contact contact) {
        return R.ok(contactService.updateById(contact));
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    public R deleteByIds(@PathVariable("ids") List<Integer> ids) {
        return R.ok(contactService.removeByIds(ids));
    }

}
